package com.coolt.client.components;

import java.util.List;

import com.coolt.client.Labels;
import com.coolt.client.Util;
import com.coolt.client.model.mock.ItemMO;
import com.coolt.client.model.Item;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class Catalogo extends DynamicTable {

	private Labels labelsConstants = GWT.create(Labels.class);
	private Util util = new Util();

	public Catalogo() {

		setTitle(labelsConstants.menuCatalogue());
		inicia(15);
		setTotalPages(10); // TO DO!!!
		carregarLista();
	}

	final AsyncCallback callbackCatalogue = new AsyncCallback() { 
		public void onSuccess(Object result) {

			setListTable((List<Item>) result);
			displayTable();
			carregarLinkPaginas();
		}

		public void onFailure(Throwable caught) {
			displayFailure();
		}
	};

	public void carregarLista() {

		writeCharging();
		Item item = new Item();
		//carregarListaStub();
		Util.getService().listaCatalogo(item, getPageSize(), getPageNow(),
		 callbackCatalogue);
	}

	private void carregarListaStub() {
		setListTable(ItemMO.listarItemMO());
		displayTable();
		carregarLinkPaginas();
	}

	public VerticalPanel showElement(int i) {

		return util.itemImageNome(((List<Item>) getListTable()).get(i));
	}
}
